$(function () {
    let form = layui.form
    form.verify({
        pwd: [
            /^[\S]{6,15}$/, '密码必须6到15位，且不能出现空格'
        ],
        newPwd: function (value) {
            let v1 = $('[name=oldPwd]').val()
            if (v1 == value) {
                return '新旧密码一致'
            }
        },
        rePwd: function (value) {
            let v2 = $('[name=newPwd]').val()
            if (v2 != value) {
                return '两次新密码不一致'
            }
        }
    })
    $('#formPwd').on('submit', function (e) {
        e.preventDefault()
        axios.post('/my/updatepwd', $(this).serialize()).then(({
            data: res
        }) => {
            if (res.status != 0) {
                return layui.layer.msg(res.message)
            }
            layui.layer.msg(res.message)
            //刷新表单
            $('#formPwd')[0].reset()
            setTimeout(() => {
                window.parent.location.href = '/login.html'
            }, 2000)
        })
    })
})